var snippet=80, viewmode='grid', tooltip=0, prevDate=1, imgWidth=100, imgHeight=100, postid='';
if(imgWidth >=imgHeight){
var postOuterWidthHeight=imgWidth+20;
}else{
var postOuterWidthHeight=imgHeight+20;
}
document.write('<style type="text/css">.post, .post h3, .post-content{display:none;}</style>');
var viewbutton='<div id="viewbutton"><a title="View as List"  href="javascript:void(0)" onclick="changeview(this)" id="list-button"><span> </span></a><a title="View as Grid"  href="javascript:void(0)" onclick="changeview(this)" id="grid-button"><span> </span></a></div>';

$(document).ready(function(){
if(viewmode != undefined){
var firstDateOuter=$('#Blog1').find('div.post-outer:first-child');
$(viewbutton).insertBefore(firstDateOuter);
}
});
function changeview(lg){
var view=lg.id;
view=view.split('-');
view=view[0];
var postOuter=$('#Blog1 div.post-outer');
if(view=='list'){
postOuter.each(function(){
$(this).addClass('list').removeClass('grid');
});
}
else{
postOuter.each(function(){
$(this).addClass('grid').removeClass('list');});
}
}

function CorrectWidthHeightRatio(ow,oh,sw,sh){
var oRatio=ow/oh, cRatio=0;
if(oRatio <1){
//********* Img Width < Img Height***************
if(oh > sh){
// Img Orig Height > variable sh which is set first.
ch=sh;
cRatio=oh/sh;
cw=ow/cRatio;
}else{
// Img Orig Height < variable sh which is set first.
ch=oh;
cw=ow;
}
}else{
//********* Img Width > Img Height****************
if(ow > sw){
// Img Orig Width > variable sw which is set first.
cw=sw;
cRatio=ow/sw;
ch=oh/cRatio;
}else{
// Img Orig Width < variable sw which is set first.
cw=ow;
ch=oh;
}
}
cw=parseInt(cw);
ch=parseInt(ch);
return {'width':cw, 'height':ch};
// End CorrectWidthHeightRatio
}

function getImg(b,c){
var imgs=$('#'+b+' img');
var img=imgs.first();
if(imgs.length >= 1){
// Found Image
var imgOrigWidth=img.width();
var imgOrigHeight=img.height();
var wh=CorrectWidthHeightRatio(imgOrigWidth,imgOrigHeight,imgWidth,imgHeight);
var imgCurWidth=wh.width;
var imgCurHeight=wh.height;
var imgSrc=imgs[0].src;
var imgAlt=imgs[0].alt;
var imgTitle=imgs[0].title;
var img='<div id="thumb-box'+b+'" onclick="goLink(this)" class="thumb-'+c+'" style="height:'+postOuterWidthHeight+'px"><img style="width:'+imgCurWidth+'px;height:'+imgCurHeight+'px" id="thumb'+b+'" onmouseover="showTip(tooltip,this,snippet)" class="thumb" src="'+imgSrc+'" alt="'+imgAlt+'" title="'+imgTitle+'" /></div><span onclick="showHidePost(this,viewmode)" class="showhide-button" id="showhide-button'+b+'">▶</span>';
}else{
// Found No Image
var img='<div class="nothumb" />';
}
return img;
}

function getA(d,c){
var postOuter=$('#'+d).parents('div:eq(2)');
var h3=postOuter.find('h3');
var a=h3.find('a');
var tagHref=a[0].href;
var tagText=h3.text();
var tagTitle=tagText;
tagText=resizetext(tagText,30);
var tag='<a href="'+tagHref+'" title="'+tagTitle+'">'+tagText+'</a>';
tag='<div id="postlink'+d+'" class="postlink-'+c+'">'+tag+'</div>';
return tag;
}

function getPrice(l,c){
var postOuter=$('#'+l).parents('div:eq(2)');
var trCaption=postOuter.find('td.tr-caption');
var trCaptionContent=trCaption.html();
trCaptionContent=trCaptionContent.split('<br>');
if(trCaptionContent.length >0){
var price=trCaptionContent[0];
var amount=postOuterWidthHeight/7;
amount=parseInt(amount);
price=resizetext(price,amount);
price='<span id="price'+l+'" class="price-'+c+'">'+price+'</span>';
}else{
price='<span id="price'+l+'" class="price-'+c+'">&nbsp;</span>';
}
return price;
}

function goLink(d){
var postOuter=$(d).parents('div:eq(2)');
var href=postOuter.find('h3 a')[0].href;
window.location = href;
}

function showTip(e,f,g){
if(e !=1){
return;
}
var tag=f.tagName;
if(tag=='IMG'){
toCut='thumb';
}else{
toCut='postlink';
}
var id=f.id;
id=id.split(toCut);
id=id[1];
var oElement = document.getElementById(id);
var targetElement = document.getElementById('tipbox');
	Cutter.run(oElement, targetElement, g, {more: ""});
var tipbox=$('#tipbox');
tipbox.find('img').remove();
tipbox.find('.tr-caption-container').remove();
var move=1;
$(document).ready(function(){
  $(document).mousemove(function(e){
if(move==1){
// put the following inside the mousemove function
var date = new Date().getTime();
if(date - prevDate > 30){
    // your code goes here
  tipbox.css({top:e.pageY+15,left:e.pageX+15});
    prevDate = date;
}
}
  });
});
tipbox.css('display','block');
f.onmouseout=function(){
tipbox.css('display','none');
tipbox.html('');
move=0;
}
}

function resizetext(i,j){
var ilength=i.length;
var islice='';
if(ilength <= j){
islice=i;
}else{
var k=ilength -j;
k=-(k+3);
islice=i.slice(0,k)+'...';
}
return islice;
};

function showHidePost(k,vm){
var showText='▶';
var hideText='▽';
var id=k.id;
id=id.split('showhide-button');
id=id[1];
var postContent=$('#'+id);
var postH3=$('#'+id).parents('div:eq(2)').find('h3.post-title');
var postContentDisplay=postContent.css('display');
var postOuter= $('#'+id).parents('div:eq(2)');
var prevOuter=postOuter.prev('.post-outer');
var nextOuter=postOuter.next('.post-outer');
var thumbBox=$('#thumb-box'+id);
var price=$('#price'+id);
if(prevOuter.length>0){
var prevOuterBorder=parseInt(prevOuter.css('borderBottomWidth'), 10);
var prevOuterClass=prevOuter.hasClass('grid-show');
if(prevOuterClass==false){
prevOuterClass=prevOuter.hasClass('list-show');
}
}else{
var prevOuterBorder=-1;
prevOuterClass=false;
}
if(nextOuter.length>0){
var nextOuterBorder=parseInt(nextOuter.css('borderTopWidth'), 10);
var nextOuterClass=nextOuter.hasClass('grid-show');
if(nextOuterClass==false){
nextOuterClass=nextOuter.hasClass('list-show');
}

}else{
var nextOuterBorder=-1;
nextOuterClass=false;
}
var thumb=$('#thumb'+id);
var postLink=$('#postlink'+id).find('a');
if(postContentDisplay=='none'){
// Show Post Content
$(k).addClass('showhide-button-hide');
$(k).text(hideText);
thumbBox.css({'border':'0 none','height':'0px'});
thumb.css({'display':'none'});
postContent.css({'display':'inline'});
postH3.css({'display':'inline'});
postLink.css('display','none');
price.css('display','none');
if(vm=='grid'){
postOuter.addClass('grid-show');
}else{
postOuter.addClass('list-show');
};
postOuter.css('width','100%');
if(prevOuterBorder<1){
postOuter.addClass('border-top');
};
if(nextOuterBorder<1){
postOuter.addClass('border-bottom');
};
if((prevOuter.length > 0) && (prevOuterClass==false)){
postOuter.addClass('margin-top');
}
if((nextOuter.length > 0) && (nextOuterClass==false)){
postOuter.addClass('margin-bottom');
}
if(prevOuter.length > 0){
prevOuter.removeClass('margin-bottom');
}
if(nextOuter.length > 0){
nextOuter.removeClass('margin-top');
}
}else{
// Hide Post Content
$(k).removeClass('showhide-button-hide');
$(k).text(showText);
thumbBox.css({'border':'1px solid #ccc','height':postOuterWidthHeight});
thumb.css({'display':'inline'});
postContent.css({'display':'none'});
postH3.css('display','none');
postLink.css('display','inline');
price.css('display','inline');
if(vm=='grid'){
postOuter.removeClass('grid-show');
postOuter.css('width',postOuterWidthHeight);
}else{
postOuter.addClass('list-show');
postOuter.css('width','100%');
};
postOuter.removeClass('border-top border-bottom margin-top margin-bottom');
if((prevOuterBorder==0) && (prevOuterClass==true)){
prevOuter.addClass('border-bottom');
}
if((nextOuterBorder==0) && (nextOuterClass==true)){
nextOuter.addClass('border-top');
}
if(prevOuterClass==true){
prevOuter.addClass('margin-bottom');
}
if(nextOuterClass==true){
nextOuter.addClass('top-bottom');
}
}
// End showHidePost function
}

function styleProduct(id,tt,sn,vm){
var postOuter=$('#'+id).parents('div:eq(2)');
var h3=postOuter.find('h3');
var thumb=getImg(id,vm);
var postlink=getA(id,vm);
var price=getPrice(id,vm);
h3.before(thumb);
h3.before(postlink);
h3.before(price);
if(vm=='grid'){
var imgthumb=$('#thumb'+id);
postOuter.css({'width':postOuterWidthHeight});
postOuter.addClass('grid');
var postOuterMarginRight='10px';
}else{
postOuter.css({'width':'100%'});
postOuter.addClass('list');
}
$('.post').show();
// End style function
}
